import os
import shutil

def replace_go_to_py():

    file_name = r"D:\python\work-test\文件操作\test1.txt"
    temp_file = r"D:\python\work-test\文件操作\test1.temp"

    temp_obj = open(temp_file,mode="w")

    with open(file_name,mode="r") as fobj:
        for line in fobj:
            if "golong" in line:
                new_line= line.replace("golong","python")
                temp_obj.write(new_line)
            else:
                temp_obj.write(line)
    temp_obj.close()

    shutil.copy(temp_file,file_name)
    os.remove(temp_file)

if __name__ == '__main__':
    replace_go_to_py()